package main

import "fmt"

func main() {
	// 有多少个 [] 就有几维

	// 1.先初始化后赋值
	var a [3][4]int
	k := 0
	for i := 0; i < len(a); i++ {
		for j := 0; j < len(a[0]); j++ {
			a[i][j] = k
			k++
		}
	}
	fmt.Println("a =", a) // a = [[0 1 2 3] [4 5 6 7] [8 9 10 11]]

	// 2.初始化并赋值
	b := [3][4]int{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}
	fmt.Println("b =", b) // b = [[1 2 3 4] [5 6 7 8] [9 10 11 12]]

	// 部分赋值
	c := [3][4]int{1: {5, 6, 7, 8}} // 赋值某行
	fmt.Println("c =", c)           // c = [[0 0 0 0] [5 6 7 8] [0 0 0 0]]

	d := [3][4]int{1: {2: 1}} // 赋值某个元素
	fmt.Println("d =", d)     // d = [[0 0 0 0] [0 0 1 0] [0 0 0 0]]
}
